package hanjia;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/17-下午4:17
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode406 {

    public int[][] reconstructQueue(int[][] people) {
        if (people.length == 1) {
            return people;
        }
        Arrays.sort(people, (a, b) -> {
            if (a[0] == b[0])
                return a[1] - b[1];
            return b[0] - a[0];

        });

        LinkedList<int[]> queue = new LinkedList<>();
        for (int [] nums :people){
            queue.add(nums[1],nums);


        }
        return queue.toArray(new int[queue.size()][] );


    }
}
